package me.ereach;

import java.util.Arrays;

public class Queue<T> {
    private T[] queue;
    private int count;

    public Queue(int size) {
        queue = (T[]) new Object[size];
    }

    public void add(Object value) {
        if (count == queue.length)
            throw new IllegalArgumentException("队列已满");

        queue[count++] = (T) value;
    }

    public T get(int index) {
        return queue[index];
    }

    public void remove() {
        if (count > 0)
            queue[--count] = null;
        else
            queue[0] = null;
    }

    @Override
    public String toString() {
        return Arrays.toString(queue);
    }
}
